package com.example.demo.controller;

import com.example.demo.core.Result;
import com.example.demo.entity.AdminPermission;
import com.example.demo.entity.AdminRole;
import com.example.demo.entity.AdminUser;
import com.example.demo.service.AdminRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 管理员角色控制器
 *
 * @author 叮当猫的百宝箱
 * @since 1.0
 */

@Tag(name = "管理员角色管理", description = "管理员用户角色相关功能")
@RestController
@RequestMapping("/adminRole")
@RequiredArgsConstructor
public class AdminRoleController {

    private final AdminRoleService adminRoleService;

    /**
     * 获取全部管理员角色列表
     *
     * @return API全局响应对象
     */
    @Operation(summary = "获取管理员角色列表")
    @GetMapping
    public Result<List<AdminRole>> getAdminRoleList() {
        List<AdminRole> roleList = adminRoleService.getAdminRoleList();
        return Result.ok(roleList);
    }

    /**
     * 根据管理员角色ID获取当前角色拥有的权限列表
     *
     * @param adminRoleId 管理员角色ID
     * @return API全局响应对象
     */
    @Operation(summary = "获取管理员角色的权限列表")
    @GetMapping("{adminRoleId}/permission")
    public Result<List<AdminPermission>> getAdminPermissionById(@PathVariable("adminRoleId") Long adminRoleId) {
        List<AdminPermission> permissionList = adminRoleService.getAdminPermissionsById(adminRoleId);
        return Result.ok(permissionList);
    }

    /**
     * 根据管理员角色ID获取有哪些用户拥有此角色
     *
     * @param adminRoleId 管理员角色ID
     * @return API全局响应对象
     */
    @Operation(summary = "获取拥有管理员角色的全部管理员用户")
    @GetMapping("{adminRoleId}/user")
    public Result<List<AdminUser>> getAdminUserById(@PathVariable("adminRoleId") Long adminRoleId) {
        List<AdminUser> adminUserList = adminRoleService.getAdminUserById(adminRoleId);
        return Result.ok(adminUserList);
    }
}
